<?php
	require 'lib/lightopenid-lightopenid/openid.php';
	
	function jackedOIDPopularProviders(){
		return array(
			"Google" => array(
							  "username" => "false",
							  "url" => "https://www.google.com/accounts/o8/id",
							  "logo" => ""
							  ),
			"Aol" => array(
							  "username" => "screenname",
							  "url" => "http://openid.aol.com/{username}",
							  "logo" => ""
							  ),
			"Yahoo" => array(
							  "username" => "false",
							  "url" => "https://me.yahoo.com",
							  "logo" => ""
							  ),
			"Flickr" => array(
							  "username" => "screenname",
							  "url" => "http://flickr.com/photos/{username}",
							  "logo" => ""
							  ),
			"Blogger" => array(
							  "username" => "blog name",
							  "url" => "http://{username}.blogspot.com/",
							  "logo" => ""
							  ),
			"Wordpress.com" => array(
							  "username" => "blog name",
							  "url" => "http://{username}.wordpress.com/",
							  "logo" => ""
							  ),
			"MyOpenID" => array(
							  "username" => "username",
							  "url" => "http://{username}.myopenid.com/",
							  "logo" => ""
							  ),
			"ClaimID" => array(
							  "username" => "username",
							  "url" => "https://claimid.com/{username}",
							  "logo" => ""
							  ),
			"Verisign" => array(
							  "username" => "false",
							  "url" => "https://pip.verisignlabs.com/",
							  "logo" => ""
							  ),
							
		);
	}
	
	function jackedOIDDoAuthRedirectEasy($providerName, $username = false){
		try{
			$providers = jackedOIDPopularProviders();
			if(in_array($providerName, $providers)){
				if($providers[$providerName][username] == 'true'){
					if(!$username)
						return false;
					$ident = preg_replace('{username}', $username, $providers[$providerName][url]);
				}else{
					$ident = $providers[$providerName][url];
				}
				jackedOIDDoAuthRedirect($ident, array('contact/email'), array('namePerson/friendly'));
			}else{
				return false;
			}
		}catch(ErrorException $e){
			return $e->getMessage();
		}
	}
	
	function jackedOIDDoAuthRedirect($identifier, $requiredFields, $optionalFields = array()){
		try{
			$openid = new LightOpenID;
			$openid->identity = $identifier;
			$openid->required = $requiredFields;
			$openid->optional = $optionalFields;
			header('Location: ' . $openid->authUrl());
		}catch(ErrorException $e){
			return $e->getMessage();
		}
    }
	
	function jackedOIDGetAuthRedirectEasy($providerName, $username = false){
		try{
			$providers = jackedOIDPopularProviders();
			if(in_array($providerName, $providers)){
				if($providers[$providerName][username] == 'true'){
					if(!$username)
						return false;
					$ident = preg_replace('{username}', $username, $providers[$providerName][url]);
				}else{
					$ident = $providers[$providerName][url];
				}
				jackedOIDGetAuthRedirect($ident, array('contact/email'), array('namePerson/friendly'));
			}else{
				return false;
			}
		}catch(ErrorException $e){
			return $e->getMessage();
		}
	}
	
	function jackedOIDGetAuthRedirect($identifier, $requiredFields, $optionalFields = array()){
		try{
			$openid = new LightOpenID;
			$openid->identity = $identifier;
			$openid->required = $requiredFields;
			$openid->optional = $optionalFields;
			return $openid->authUrl();
		}catch(ErrorException $e){
			return $e->getMessage();
		}
	}
	
	function jackedOIDHandleAuthResponse(){
		try{
			$openid = new LightOpenID;
			if($openid->validate()){
				$data = $openid->getAttributes();
				$data['identity'] = $openid->identity;
				return $data;
			}else
				return false;
		}catch(ErrorException $e){
			return $e->getMessage();
		}
	}

?>